<template>
    <div class="setfastproinfo">
        <el-form :label-position="labelPosition" label-width="120px" :model='form' :rules="rules" ref="form">
            <el-form-item label="商品类目" v-if="!isEdit">
                {{proCategory.category}}>{{proCategory.type}}>{{proCategory.brand}}>{{proCategory.model}}
            </el-form-item>
            <el-form-item label="商品类目" v-if="isEdit">
                {{info.goods.category}}>{{info.goods.type}}>{{info.goods.brand}}>{{info.goods.model}}
            </el-form-item>
            <!--<el-form-item label="店铺分类">
                <el-select v-model="form.shopid1" @change="firCateChoosed">
                    <el-option
                            v-for="item in shopCate1"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id">
                    </el-option>
                </el-select>
                <el-select v-model="form.shopid2" prop="shopid2">
                    <el-option
                            v-for="item in shopCate2"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>-->
            <el-form-item label="新旧程度" prop="oldLevel">
                <el-select v-model="form.oldLevel" style="width: 325px;">
                    <el-option
                            v-for="item in oldDeg"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="支付方式">
                *30天（含）以下租金一次性支付，60天以上租金每30天支付一次
            </el-form-item>
            <el-form-item label="意外保险（元）" prop="accidentInsurance">
                <el-input v-model="form.accidentInsurance" style="width: 325px;">

                </el-input>
            </el-form-item>

            <el-form-item label="保险范围" v-if="JSON.stringify(proCategory)!=='{}' || JSON.stringify(info)!=='{}'"
                          style="margin-bottom: 0;">
                <div class="tipText" v-for="item in assureItems" :key="item.id">
                    <el-checkbox v-model="item.isChecked">
                        {{item.name}}
                    </el-checkbox>
                    <el-tooltip class="item" effect="dark" :content="item.detail" placement="bottom"
                                popper-class="textTip">
                        <i class="icon fa fa-question-circle-o"></i>
                    </el-tooltip>
                </div>

            </el-form-item>

            <!--<el-button type="text" style="width: 80px;margin-left: 30px;" @click="setAssure=true">自定义保险项</el-button>-->
            <!--<el-form ref="assureform" :model="assureForm"-->
            <!--style="border: 1px solid #ccc;width: 600px;height: 300px;margin: 20px;padding:70px 0 0 45px;box-sizing: border-box;display: inline-block;vertical-align: top;"-->
            <!--v-if="setAssure">-->
            <!--<el-form-item>-->
            <!--<el-input placeholder="请输入保险项名称" v-model="assureForm.name" style="width: 325px;"></el-input>-->
            <!--</el-form-item>-->
            <!--<el-form-item>-->
            <!--<el-input type="textarea" v-model="assureForm.detail" placeholder="请输入保险详细描述"-->
            <!--style="width: 515px;"></el-input>-->
            <!--</el-form-item>-->
            <!--<el-form-item>-->
            <!--<el-button type="primary" @click="addAssure">添加</el-button>-->
            <!--<el-button @click="cancelAddAssure">取消</el-button>-->
            <!--</el-form-item>-->
            <!--</el-form>-->

            <el-form-item label="特色服务" v-if="JSON.stringify(proCategory)!=='{}' || JSON.stringify(info)!=='{}'">
                <div class="tipText" v-for="item in speciItems" :key="item.id">
                    <el-checkbox v-model="item.isChecked">{{item.name}}</el-checkbox>
                    <el-tooltip class="item" effect="dark" :content="item.detail" placement="bottom"
                                popper-class="textTip">
                        <i class="icon fa fa-question-circle-o"></i>
                    </el-tooltip>
                </div>
                <br/>
                <span v-if="num>=4" style="color: red;">特色服务至多勾选四项</span>
                <span v-if="num==0" style="color: red;">您还未选择特色服务，提交时会自动帮您勾选包邮速达一项</span>
            </el-form-item>

            <el-form-item label="是否支持买断" prop="buyout">
                <el-checkbox v-model="form.buyout">支持买断</el-checkbox>
                <el-tooltip class="item" effect="dark" content="买断款=租赁物原价（签约价）*120%－用户已付租金" placement="bottom"
                            popper-class="textTip">
                    <i class="icon fa fa-question-circle-o"></i>
                </el-tooltip>
            </el-form-item>

            <el-form-item label="租赁期限" required prop="leaseDays"
                          v-if="JSON.stringify(proCategory)!=='{}' || JSON.stringify(info)!=='{}'">
                <el-checkbox-group v-model="form.leaseDays">
                    <el-checkbox v-for="item in renttimeoptions" :label="item+'天'" :key="item">
                    </el-checkbox>
                </el-checkbox-group>
            </el-form-item>
            <el-form-item label='是否支持续租' prop="renew">
                <el-checkbox v-model="form.renew" @change="handleCheckAllChange">支持续租
                </el-checkbox>
            </el-form-item>

            <el-form-item v-show="form.renew" label='请选择续租租期'>
                <div v-if="form.leaseDays.length > 0">
                    <el-checkbox-group v-model="renewDays" @change="handleCheckedCitiesChange">
                        <el-checkbox v-for="item in form.leaseDays" :label="item" :key="item">
                        </el-checkbox>
                    </el-checkbox-group>
                </div>
                <div v-if="form.leaseDays.length <= 0">
                    <span style="color: red;">请先选择商品租期</span>
                </div>
            </el-form-item>
        </el-form>

        <choose-speci :speci-groups="speciGroups" @get-speci-name="getSpeciName" @add-speci="addSpeci"
                      v-if="this.speciGroups.length!==0" :lease-days="form.leaseDays"></choose-speci>

        <!--批量设置按钮-->
        <el-button type="primary" size="large" @click="handleSetRent(selectedItems)" style="margin-bottom: 20px;">批量设置
        </el-button>
        <el-button size="large" @click="deleteSetRent(selectedItems)" style="margin-left: 20px;">
            批量删除
        </el-button>
        <el-dialog title="将以上商品的租金设置为" :visible.sync="batchSet" custom-class="setRentDialog">
            将以上商品的
            <el-select v-model="currentSet" placeholder="请选择" style="margin-bottom: 20px;width: 80px;">
                <el-option
                        v-for="item in batchSetItems"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                        :disabled="item.disable">
                </el-option>
            </el-select>
            设置为
            <el-input v-model="batchSetVal" style="width: 150px;"></el-input>

            <div slot="footer" class="dialog-footer">
                <el-button @click="batchSet = false">取 消</el-button>
                <el-button type="primary" @click="setRentAll">确 定</el-button>
            </div>
        </el-dialog>

        <!--表格处理-->
        <el-table
                :data="speciTable"
                border
                style="width:100%;"
                @selection-change="selectHandleChange">
            <el-table-column
                    type="selection"
                    width="55">
            </el-table-column>
            <el-table-column v-for="(item,index) in specisTitle" :label="item" :key="index" :prop="'param'+(index+1)"
                             width="120">

            </el-table-column>
            <el-table-column label="租期(天)" prop="leaseDay">

            </el-table-column>
            <el-table-column label="原价">
                <template slot-scope="scope">
                    <el-input v-model="scope.row.originalPrice"></el-input>
                </template>
            </el-table-column>
            <el-table-column label="租金(元/天)">
                <template slot-scope="scope">
                    <el-input v-model="scope.row.rent"></el-input>
                </template>
            </el-table-column>
            <el-table-column
                    label="操作">
                <template slot-scope="scope">
                    <el-button
                            @click.native.prevent="deleteRow(scope.$index,speciTable)"
                            type="text"
                            size="small">
                        删除
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="editBtn" style="margin-top: 24px">
            <el-button @click="commitCheck()" type="primary" :disabled="!canpublish">提交审核</el-button>
            <el-dialog
                    title="
是否确认提交审核？"
                    :visible.sync="dialogVisible"
                    size="tiny">
                <span>后台审核2个工作日，通过后商品将会进入仓库中，请耐心等待！</span>
                <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="confirmSummit">确 定</el-button>

  </span>
            </el-dialog>

            <el-button @click="backToPublish" v-if="!isEdit">取消发布</el-button>

        </div>
    </div>
</template>

<script>
    import {getProParams, productPublishFast, getStanderdTemplate} from '@/api/fastPublish';
    import {getShopCate, getSpecItem, getAssure} from '@/api/normalPublish';
    import chooseSpeci from './components/chooseSpeci';
    import {IntergerIncludeZero, IsNum, isInterger, isNumber, hasContain, isNumberZ, isIllegal} from '@/utils/validate';
    import {showMessage} from '@/utils/message';
    import {getTab, setTab} from '@/utils/list';
    export default {
        components: {chooseSpeci},
        props: {
            proCategory: {
                type: Object,
                default: () => {
                    return {}
                }
            },
            info: {
                type: Object,
                default: () => {
                    return {}
                }
            },
            isEdit: {
                type: Boolean,
                default: false
            }
        },
        data() {
            let validatorMoney = (rule, value, callback) => {
                if (!isNumberZ(value)) {
                    callback(new Error('请输入数字!'))
                }
                callback()
            };
            return {
                setAssure: false,
//                自定义保险项
                assureForm: {
                    name: '',
                    desc: '',
                },
                rules: {
                    accidentInsurance: [
                        {required: true, message: '不能为空'},
                        {validator: validatorMoney, trigger: 'blur'}
                    ],
                    leaseDays: [
                        {type: 'array', required: true, message: '请至少选择一个租期', trigger: 'change'}
                    ],
                },
                form: {
//                    shopid1: '',
//                    shopid2: '',
                    oldLevel: 7,
                    accidentInsurance: '',
                    leaseDays: [],
                    buyout: false,
                    renew: false
                },

                dialogVisible: false,
//                租期勾选
//                renew: false,//是否支持续租
                renewDays: [],
                specisTitle: [],
                speciTable: [],
                speciGroups: [],
                support: false,
                fashion: false,
                newPro: false,
                labelPosition: 'right',
//        待定根据 innerCategoryId 来请求接口 返回 一级和二级 分类
                shopCate1: [],
                shopCate2: [],
                oldDeg: [
                    {
                        id: 5,
                        name: '5成新'
                    },
                    {
                        id: 6,
                        name: '6成新'
                    },
                    {
                        id: 7,
                        name: '7成新'
                    },
                    {
                        id: 8,
                        name: '8成新'
                    },
                    {
                        id: 9,
                        name: '9成新'
                    },
                    {
                        id: 10,
                        name: '全新'
                    }
                ],

                prodoctInventoryData: [],
                list: [],
                assureItems: [
//                    {
//                        isChecked: false,
//                        name:"a",
//                        id:0
//                    }
                ],
                speciItems: [],
                dataSend: {},
                renttimeoptions: [],
                fastPublishParams: {},
                currentSet: 'SETRENT',
                batchSetItems: [
                    {
                        value: 'SETRENT',
                        label: '租金',
                        disable: false,
                    },
                    {
                        value: 'SETPRICE',
                        label: '原价',
                        disable: false
                    }
                ],
                batchSetVal: '',//批量设置租金
                selectedItems: [],
                batchSet: false,
                newAssureItems:[],
            }
        },
        computed: {
            canpublish() {
                let items = this.speciTable || [];
                let checkedItems = []; //選中的租期及租金
                if (items.length) {
                    for (let item of items) {
                        if (item.rent) {
                            checkedItems.push(item);
                        }
                    }
                }

                return checkedItems.every(item => {
                    let rent = item.rent || '';
                    let price = item.originalPrice || '';
                    if (!isNumber(rent)) {
                        this.$message.error('请输入合法的金额');
                    }
                    if (!isNumber(price)) {
                        this.$message.error('请输入合法的金额');
                    }
                    return isNumber(rent) && isNumber(price);
                });
                return false;
            },
            num(val) {
                let t = 0;
                for (let item of this.speciItems) {
                    if (item.isChecked) {
                        t++;
                    }
                }
                return t;
            },
            renderDatas: {
                get: function () {
                    return this.info
                },
                set: function (value) {
                    this.info = value; //最后修改了msg
                }
            },
        },
        methods: {
//            全选
            handleCheckAllChange(val) {
//                console.log(val);
                this.renewDays = val ? this.form.leaseDays : [];
                if (!this.form.renew) {
                    this.renewDays = []
                }
            },
            handleCheckedCitiesChange(value) {
//                选择
                let checkedCount = value.length;
                this.form.renew = checkedCount != 0;

            },
            renderData() {
//回显
//                显示租期
                if (JSON.stringify(this.renderDatas) != '{}') {
                    /*let data1= {
                        "categoryId": this.info.goods.categoryId,
                        "typeId": this.info.goods.typeId,
                        "brandId": this.info.goods.brandId,
                        "modelId": this.info.goods.modelId
                    };*/
                    this.renttimeoptions = this.renderDatas.goods.templateLeaseDays.split(',').length ? this.renderDatas.goods.templateLeaseDays.split(',') : [];
//保险范围
                    let ids = {
                        "categoryId": this.renderDatas.goods.categoryId,
                        "typeId": this.renderDatas.goods.typeId
                    };

                    getAssure(ids).then((resp) => {
//                        console.log(resp);
                        let data = resp.data;
                        for (let item of data) {
                            let insuarance = {
                                name: item.insuranceName,
                                id: item.id,
                                isChecked: false,
                                detail: item.detail
                            };
                            this.assureItems.push(insuarance);
                        }
                        if (this.renderDatas.insuranceIds) {
                            let arr = this.renderDatas.insuranceIds.split(',');
                            let item;
                            for (item of arr) {
                                for (let items of this.assureItems) {
                                    if ((item - 0) == items.id) {
                                        items.isChecked = true;
                                    }
                                }
                            }
                        }
                    }).catch((err) => {
//                        console.log(err)
                    });
                    getSpecItem(ids).then((resp) => {
//                        console.log(resp);
                        let data = resp.data;
                        for (let item of data) {
                            let speciItem = {
                                name: item.name,
//                            注意字段名
                                id: item.id,
                                isChecked: false,
                                detail: item.detail
                            };
                            this.speciItems.push(speciItem)
                        }
                        if (this.renderDatas.characteristicIds) {
                            let arr = this.renderDatas.characteristicIds.split(',');
                            let item;
                            for (item of arr) {
                                for (let items of this.speciItems) {
                                    if ((item - 0) == items.id) {
                                        items.isChecked = true;
                                    }
                                }
                            }
                        }
                    }).catch((err) => {
//                        console.log(err)
                    })
                }

//                获取规格
                let arr = [];

//                this.speciGroups = this.info.goodsSpecificationList;
//                规格的顺序
                for (let item of this.renderDatas.goodsSpecificationList) {
                    if (item.specification == 'specificationFirst') {
                        arr[0] = item;
                    }
                    if (item.specification == 'specificationSecond') {
                        arr[1] = item;
                    }
                    if (item.specification == 'specificationThird') {
                        arr[2] = item;
                    }
                    if (item.specification == 'specificationFouth') {
                        arr[3] = item;
                    }
                    if (item.specification == 'specificationFifth') {
                        arr[4] = item;
                    }
                }
                this.speciGroups = arr;

//                console.log(this.speciGroups);
//                渲染数据
                let rentAndLeasedays = this.renderDatas.specificationCombinationList;
                for (let item of rentAndLeasedays) {
                    let data = {
                        param1: item.specificationFirst ? item.specificationFirst : '',
                        param2: item.specificationSecond ? item.specificationSecond : '',
                        param3: item.specificationThird ? item.specificationThird : '',
                        param4: item.specificationFourth ? item.specificationFourth : '',
                        param5: item.specificationFifth ? item.specificationFifth : '',
                        leaseDay: (item.leaseDay - 0) + '天',
                        rent: item.rent / 100,
                        originalPrice: isNaN(item.originalPrice / 100)?0:item.originalPrice / 100
                    };
//                    originalPrice字段还未部署
                    this.speciTable.push(data);
                }

                this.form.oldLevel = this.renderDatas.goods.oldLevel - 0;
                this.form.accidentInsurance = this.renderDatas.goods.accidentInsurance / 100;
                this.form.buyout = this.renderDatas.goods.buyout;
                this.form.leaseDays = this.renderDatas.goods.leaseDays.split(',').length ? this.renderDatas.goods.leaseDays.split(',').map(item => {
                    return item + '天'
                }) : [];
                this.form.renew = this.renderDatas.goods.renew;
                this.renewDays = this.renderDatas.goods.renewDays.split(',').length ? this.renderDatas.goods.renewDays.split(',').map(item => {
                    return item + '天'
                }) : [];
            },
            getSpeciName(value) {
//                console.log('拿到了表格名称' + value);
                this.specisTitle = value;
            },
            addSpeci(value) {
//                console.log(value);
                /*if (this.isEdit) {*/
//                    编辑
                let array=[];
                let results = new Array();　 //创建一个数组
                for (let item of this.speciGroups) {
                    array.push(item.specificationJson);
                }
//                console.log(array);
                let len = array.length;
                let indexs = {};

                function GetResults(start) {
                    start++;
                    if (start > len - 1) {
                        return;
                    }
                    if (!indexs[start]) {
                        indexs[start] = 0;
                    }
                    if (!(array[start] instanceof Array)) {
                        array[start] = [array[start]];
                    }
                    for (indexs[start] = 0; indexs[start] < array[start].length; indexs[start]++) {
                        GetResults(start);
                        if (start == len - 1) {
                            var temp = [];
                            for (var i = len - 1; i >= 0; i--) {
                                if (!(array[start - i] instanceof Array)) {
                                    array[start - i] = [array[start - i]];
                                }
                                temp.push(array[start - i][indexs[start - i]]);
                            }
                            results.push(temp);
                        }
                    }
//                    console.log(results);
                    return results;
                }
                let sku=GetResults(-1);
//                console.log(sku);
                for(let i=0;i<value.length;i++){
                    if(value[i]){
                        for(let item of sku){
                            item[i]=value[i];
                        }
                    }

                }
//                console.log(sku);
                Array.prototype.unique3 = function(){
                    var res = [];
                    var json = {};
                    for(var i = 0; i < this.length; i++){
                        if(!json[this[i]]){
                            res.push(this[i]);
                            json[this[i]] = 1;
                        }
                    }
                    return res;
                };
                sku=sku.unique3();
                console.log(sku.unique3());
                let cl = this.form.leaseDays;
                for(let item of sku){
                    for (let i = 0; i < cl.length; i++) {
                        let data =
                            {
                                param1: item[0] ? item[0] : '',
                                param2: item[1] ? item[1] : '',
                                param3: item[2] ? item[2] : '',
                                param4: item[3] ? item[3] : '',
                                param5: item[4] ? item[4] : '',
                                leaseDay: cl[i],
                                rent: '',
                                originalPrice: '',
                            };
                        let a = true;
//                        假设都不一样
                        for (let i = this.speciTable.length - 1; i >= 0; i--) {
                            let item1 = this.speciTable[i];
                            if (data.param1 == item1.param1 && data.param2 == item1.param2 && data.param3 == item1.param3 && data.param4 == item1.param4 && data.param5 == item1.param5 && data.leaseDay == item1.leaseDay) {
                                this.$message.error('已经存在相同规格和租期的商品，请勿重复添加！！！');
                                a = false;
                            }
                        }
                        //没有相同的 就添加
                        if (a) {
                            this.speciTable.push(data);
                        }

                    }
                }

            },
            /*shopFirCate() {
    //                根据一级分类渲染二级
                console.log(this.$store.getters.id);
                getShopCate(this.$store.getters.id)
                    .then((resp) => {
                        console.log(resp);
                        this.list = resp.data.list;
                        for (let item of this.list) {
                            let firCate = {
                                name: item.name,
                                id: item.id
                            };
                            this.shopCate1.push(firCate)
                        }
                    }).catch((err) => {
                    console.log(err)
                })
            },
            firCateChoosed(value) {
    //                店铺二级分类
                console.log(value);
                for (let item of this.list) {
                    if (value == item.id) {
                        if (item.children == null) {
                            return
                        } else {
                            for (let item1 of item.children) {
                                let secCate = {
                                    name: item1.name,
                                    id: item1.id
                                };
                                this.shopCate2.push(secCate)
                            }
                        }
                    }
                }
            },*/
            getProci() {
//               获取规格
                getProParams(this.proCategory.id)
                    .then((resp) => {
//                        console.log(resp);
                        this.speciGroups = resp.data;
                    })
                    .catch((err) => {
//                        console.log(err)
                    })
            },
            getAssureAndSpec() {
                this.dataSend = this.proCategory;
                let data = {
                    categoryId: this.proCategory.categoryId,
                    typeId: this.proCategory.typeId
                };
//                console.log(data);

                getAssure(data).then((resp) => {
//                    console.log(resp);
                    let data = resp.data;
                    for (let item of data) {
                        let insuarance = {
                            name: item.insuranceName,
                            id: item.id,
                            isChecked: false,
                            detail: item.detail
                        };
                        this.assureItems.push(insuarance)
                    }
                }).catch((err) => {
//                    console.log(err)
                });

                getSpecItem(data).then((resp) => {
//                    console.log(resp);
                    let data = resp.data;
                    for (let item of data) {
                        let speciItem = {};
                        if (item.name == '包邮速达') {
                            speciItem = {
                                name: item.name,
//                            注意字段名
                                id: item.id,
                                isChecked: true,
                                detail: item.detail
                            };
                        } else {
                            speciItem = {
                                name: item.name,
//                            注意字段名
                                id: item.id,
                                isChecked: false,
                                detail: item.detail
                            };
                        }

                        this.speciItems.push(speciItem)
                    }
                }).catch((err) => {
//                    console.log(err)
                })
            },
            deleteRow(index, rows) {
                rows.splice(index, 1);
            },
            getrenttimeoptions() {
                this.renttimeoptions = this.proCategory.leaseDays.split(',');
//                得到数组[60,90,120]
            },
            add(value) {
//                console.log(value);
            },
            commitCheck(formName) {
                let group1, group2, group3, group4;
                if (this.isEdit) {
//                    编辑商品
                    group1 = {
                        "goods": {
                            "oldLevel": this.form.oldLevel - 0,
                            "accidentInsurance": (this.form.accidentInsurance - 0) * 100,//num
                            "buyout": this.form.buyout,
                            'renew': this.form.renew,
                            "renewDays": this.renewDays.length ? (this.renewDays.map(item => {
                                return item.slice(0, item.length - 1)
                            })).join() : '',
                        }
                    };

                    if (JSON.stringify(this.renderDatas) != '{}') {
                        group1.goods.id = this.renderDatas.goods.id;
                        group1.goods.standardizedTemplateId = this.renderDatas.goods.standardizedTemplateId;
                    }


                } else {
//                发布数据
                    group1 = {
                        "goods": {
//                            "innerCategoryId": this.form.shopid2 - 0,//num
                            "oldLevel": this.form.oldLevel - 0,
                            "accidentInsurance": (this.form.accidentInsurance - 0) * 100,//num
                            "standardizedTemplateId": this.proCategory.id, //num
                            "buyout": this.form.buyout,
                            'renew': this.form.renew,
                            "leaseDays": this.form.leaseDays.length ? (this.form.leaseDays.map(item => {
                                return item.slice(0, item.length - 1)
                            })).join() : '',
                            "renewDays": this.renewDays.length ? (this.renewDays.map(item => {
                                return item.slice(0, item.length - 1)
                            })).join() : '',
                        }
                    };
                }
                group2 = {
                    goodsSpecifications: {
                        insertList: []
                    }
                };
                let leaseDaysArr = [];
                for (let item of this.speciTable) {
//                    租期存在

                    if (item.rent && item.originalPrice && item.rent != '0.0' && item.rent != '0.00' && item.originalPrice != '0.0' && item.originalPrice != '0.00') {

                        let a = {
                            specificationFirst: item.param1,
                            specificationSecond: item.param2,
                            specificationThird: item.param3,
                            specificationFourth: item.param4,
                            specificationFifth: item.param5,
                            leaseDay: item.leaseDay.slice(0, item.leaseDay.length - 1) - 0,
                            rent: item.rent * 100,
                            originalPrice: item.originalPrice * 100,
                        };

                        group2.goodsSpecifications.insertList.push(a);
//                        处理租期
                        if (!hasContain(leaseDaysArr, item.leaseDay.slice(0, item.leaseDay.length - 1))) {
                            leaseDaysArr.push(item.leaseDay.slice(0, item.leaseDay.length - 1));
                        }

                    } else {
                        this.$message.error('您还有商品未设置租金或原价');
                        return;
                    }
                }
                let renewDaysArr = group1.goods.renewDays.split(',');
                for (let i = renewDaysArr.length - 1; i >= 0; i--) {
                    let item = renewDaysArr[i];
                    if (!hasContain(leaseDaysArr, item)) {
                        renewDaysArr.splice(i, 1);
                    }
                }
                group1.goods.leaseDays = leaseDaysArr.join();
                group1.goods.renewDays = renewDaysArr.join();
                group3 = {
                    "insuranceIds": ''
                };
                if (this.assureItems.length) {
                    let arr1 = [];
                    for (let item of this.assureItems) {
                        if (item.isChecked) {
//                        被勾选
                            arr1.push(item.id)
                        }
                    }

                    let str1 = arr1.join();
//                        console.log(str1);
                    group3 = {
                        "insuranceIds": str1
                    };
                }
                group4 = {
                    "characteristicIds": ''
                };
                //                特色项
                if (this.speciItems.length) {
                    let arr2 = [];
                    for (let item of this.speciItems) {
                        if (item.isChecked) {
//                        被勾选
                            arr2.push(item.id)
                        }
                    }
                    if (arr2.length > 4) {
                        this.$message({
                            type: 'warning',
                            message: '特色服务至多勾选四项'
                        });
                        return;
                    }
                    //                        如果一项都没有选
                    if (!arr2.length) {
                        for (let item of this.speciItems) {
                            if (item.name == '包邮速达') {
                                item.isChecked = true;
                                arr2.push(item.id);
                            }
                        }
                    }
                    let str2 = arr2.join();
//                        console.log(str2);
                    group4 = {
                        "characteristicIds": str2
                    };
                }

                let newAssure={};
                if(this.newAssureItems.length){
                    newAssure={
                        addAssureItems:[]
                    };
                    for(let item of this.newAssureItems){
                        if(item.isChecked){
                            let a={
                                name:item.name,
                                detail:item.detail
                            };
                            newAssure.addAssureItems.push(a);
                        }
                    }
                }
                this.fastPublishParams = Object.assign({}, group1, group2, group3, group4,newAssure);
//                console.log(this.fastPublishParams);
                this.$refs.form.validate((valid) => {
                    if (valid) {
                        this.dialogVisible = true;
                    } else {
                        return false;
                    }

                });
            },
            confirmSummit() {
                if (this.fastPublishParams) {
                    this.dialogVisible = false;
                    productPublishFast(this.fastPublishParams)
                        .then((resp) => {
//                            console.log(resp);
                            if (this.isEdit) {
                                showMessage({
                                    type: 'success',
                                    title: '商品修改成功',
                                    message: ''
                                });
                                setTab('product-status-check-pending');
                                this.$emit('cancel-edit');
                            } else {
                                showMessage({
                                    type: 'success',
                                    title: '商品发布成功',
                                    message: ''
                                });
                                setTab('product-status-check-pending');
                                this.$router.push({name: 'goodsList'});
                            }
                        }).catch((err) => {
                        this.$message.error('请求超时，请稍后再试！');
                    })
                }
            },
            backToPublish() {
                this.$confirm('您要发布的商品信息将会丢失, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.$router.push({name: 'goodsPublish'})
                }).catch(() => {

                });
            },
            cancelEdit() {
//                取消编辑
                this.$confirm('您要编辑的商品信息将会丢失, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.$router.push({name: 'goodsList'})

                }).catch(() => {
                });
            },
            selectHandleChange(val) {
                let arr = val;
                let indexs = [];
                for (let i = 0; i < arr.length; i++) {
                    let data = arr[i];
                    for (let j = 0; j < this.speciTable.length; j++) {
                        let item = this.speciTable[j];
                        if (data.param1 == item.param1 && data.param2 == item.param2 && data.param3 == item.param3 && data.param4 == item.param4 && data.param5 == item.param5 && data.leaseDay == item.leaseDay) {
//                           相同
                            indexs.push(j);
                        }
                    }
                }
                this.selectedItems = indexs;
            },
            handleSetRent() {
                if (this.selectedItems.length) {
                    this.batchSet = true;
                } else {
                    this.$message.error('您还没有选择需要批量设置的商品！');
                }

            },
            setRentAll() {
//                批量设置租金
                if (!isNumber(this.batchSetVal)) {
                    this.$message.error('请输入合法的金额');
                    return;
                }
                if (this.batchSetVal == '0.0') {
                    this.$message.error('请输入合法的金额');
                    return;
                }
                if (this.batchSetVal == '0.00') {
                    this.$message.error('请输入合法的金额');
                    return;
                }
                if (this.currentSet == 'SETRENT') {
                    for (let i = 0; i < this.selectedItems.length; i++) {
                        let index = this.selectedItems[i];
                        for (let j = 0; j < this.speciTable.length; j++) {
                            let item = this.speciTable[j];
                            if (index == j) {
//                           索引相同
                                item.rent = this.batchSetVal;
                            }
                        }
                    }
                }
//                批量设置原价接口还没实现
                if (this.currentSet == 'SETPRICE') {
                    for (let i = 0; i < this.selectedItems.length; i++) {
                        let index = this.selectedItems[i];
                        for (let j = 0; j < this.speciTable.length; j++) {
                            let item = this.speciTable[j];
//                            console.log(item);
                            if (index == j) {
//                           索引相同
                                item.originalPrice = this.batchSetVal;
                            }
                        }
                    }
                }
                this.batchSet = false;
            },
            addAssure() {
//                 添加保险项  点击后框框消失 assureitem里push一组数据
                if (!this.assureForm.name || !this.assureForm.detail) {
                    this.$message.error('请填写完整保险项');
                    return;
                }
                if (isIllegal(this.assureForm.name)) {
//                    不合法
                    this.$message.error('保险项名称请勿填写非法字符');
                    return;
                }
                if (isIllegal(this.assureForm.detail)) {
//                    不合法
                    this.$message.error('保险项描述请勿填写非法字符');
                    return;
                }

                let temp={
                    name: this.assureForm.name,
//                            注意字段名
                    isChecked: true,
                    detail: this.assureForm.detail,
                };
                this.assureItems.push(temp);
                this.newAssureItems.push(temp);
                this.assureForm = {};
            },
            cancelAddAssure() {
                this.setAssure = false;
                this.assureForm = {};
            },
            deleteSetRent(){
                if (this.selectedItems.length) {
                    console.log(this.selectedItems);
                    this.$confirm('此操作将删除选中规格的商品, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
//                        删除选中的商品

                        for (let i = this.selectedItems.length; i >=0 ; i--) {
                            let index = this.selectedItems[i];
                            console.log(index);
                            for(let j=this.speciTable.length;j>=0;j--){

                                if(j==index){
                                    console.log(j);
                                    this.speciTable.splice(j,1);
                                }
                            }
                        }
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                    }).catch(() => {

                    });
                } else {
                    this.$message.error('您还没有选择需要批量删除的商品！');
                }
            }
        }
        ,
        mounted() {
            if (this.isEdit) {
                this.renderDatas = this.info;
                setTimeout(this.renderData, 500)
            } else {
                setTimeout(this.getProci, 300);
//            this.shopFirCate();
                setTimeout(this.getAssureAndSpec, 300);
                setTimeout(this.getrenttimeoptions, 300);
            }
        }
        ,
    }
</script>

<style lang="less">
    .setfastproinfo {
        .el-form {
            .el-form-item {
                .el-form-item__content {
                    width: 880px;
                }
            }
        }

        .tipText {
            display: inline-block;
            margin: 0 10px;
        }

        .el-tooltip__popper {
            &.is-light {
                background: transparent;
                border: none;
                color: red;
                .popper__arrow {
                    display: none;
                }
            }
        }

        .setRentInp {
            width: 50px;
            display: inline-block
        }

        .el-table__empty-block {
            min-height: 61px;
        }
        .editBtn {
            display: block;
            text-align: center;
            margin-top: 24px;
            .el-button {
                margin-left: 40px;
            }
        }
        .setRentDialog {

        }
    }


</style>

